//详细地址
var locationDetailInfoDialog;
require(['grid', 'topBar', 'date', 'layout'], function () {

    var $mainGrid = $('#grid1'),
        $detailGrid = $('#grid2');
    $('#top').topBar({
        left: [
            {
                type: 'filter-more',
                dateType:'custom',
                search: function () {
                    $detailGrid.clearGridData();
                    var nodes = commonFun.getLeftTreeSelectedNodes();
                    if (nodes.length < 1 || nodes[0].type != "LINE") {
                        $.messager.alert("提示", "请选择查询线路", "info");
                        return;
                    }
                    var $postData = $(this).getValues();
                    $postData.lineIds = nodes[0].id;
                    $mainGrid.grid('setGridParam', {
                        datatype: "json",
                        postData: $postData
                    }).trigger("reloadGrid");
                },
                item: [
                    {
                        text: '时间快捷',
                        name1: 'beginTime',
                        name2: 'endTime',
                        type: 'dateLine'
                    }
                ]
            }
        ]
    });

    $('body').layout();

    $mainGrid.grid({
        url: "/electronicSign/getElectronicSignCountData.htm",
        multiselect: false,
        colModel: [
            {name: "carId", label: 'carId', key: true, hidden: true},
            {name: "licPltNo", label: "车牌号", width: "80"},
            {
                name: "errorCount", label: "异常次数", align: "right", width: "100",
                formatter: 'customCurrency',
                formatoptions: {
                    css: 'numBlueBtn',
                    clickFn: function (rowData) {
                        querySlotMachine(rowData.carId, '1');
                    }
                }
            },
            {
                name: "normalCount", label: "正常次数", align: "right", width: "100",
                formatter: 'customCurrency',
                formatoptions: {
                    css: 'numBlueBtn',
                    clickFn: function (rowData) {
                        querySlotMachine(rowData.carId, '0');
                    }
                }
            }
        ],
        showPager: false
    });

    $detailGrid.grid({
        url: "/electronicSign/getElectronicSignDetail.htm",
//        showPager: false,
        multiselect: false,
        colModel: [
            {name: "rcrdId", label: "id", key: true, hidden: true},
            {name: "loLgt", label: "loLgt", hidden: true},
            {name: "loLtt", label: "loLtt", hidden: true},
            {name: "licPltNo", label: "车牌号"},
            {name: "drvName", label: "驾驶员"},
            {name: "swtcSt", label: "开关信号"},
            {name: "rcrdTime", label: "发生时间"},
            {name: "detailAddre", label: "具体地点",
                formatter: 'operArea',
                formatoptions: [
                    {
                        text: '详细位置',
                        css:'operate-scan',
                        click: function (data) {
                            showDataDetail(data);
                        }
                    }
                ]
            }
        ]
    });

    function querySlotMachine(carId, type) {
        var $postData = $("#top").parent().getValues();
        $postData.carId = carId;
        $postData.type = type;
        $detailGrid.grid('setGridParam', {
            page: 1,
            datatype: "json",
            postData: $postData
        }).trigger("reloadGrid");
    }

    //-- 显示 详细位置信息
    showDataDetail = function (data) {
        openLocationDetailInfoDialog("详细位置", data); //弹出的标题和数据
    };

    function openLocationDetailInfoDialog(title, data) {
        if (!locationDetailInfoDialog) {
            locationDetailInfoDialog = $('<div>').dialog({
                title: title,
                url: './common/map/mapLocation.htm',
                height: $(window.parent).height() * 0.8,
                width: $(window.parent).width() * 0.85
            });
        }
        locationDetailInfoDialog.dialog('open');
        locationDetailInfoDialog.dialog('exec', 'showMapLocation', data);
    }

});
